/**
 * Created by dev-001 on 2017/2/28.
 */
import url from 'url';
import path from 'path';
import fs from 'fs';

export const log = {
    all: path.join(__dirname, '../logs/all.log'),
    trace: path.join(__dirname, '../logs/trace.log'),
    debug: path.join(__dirname, '../logs/debug.log'),
    info: path.join(__dirname, '../logs/info.log'),
    warn: path.join(__dirname, '../logs/warn.log'),
    error: path.join(__dirname, '../logs/error.log'),
    fatal: path.join(__dirname, '../logs/fatal.log')
}

export const staticServ = {
    host: 'http://test.zhixiaocloud.com',
    qiniuhost: 'http://onkk6zl0a.bkt.clouddn.com'
}

export const mongoConfig = {
    host: 'mongodb://120.77.80.118',
    port: 27017,
    db: 'zxy_dev',
    pwd: ''
};
// export const mongoConfig = {
//     host: 'mongodb://127.0.0.1',
//     port: 27017,
//     db: 'test',
//     pwd: ''
// };
export const redisConfig = {
    host: 'localhost' || '120.77.80.118',
    port: 6379,
    db: 0,
    pwd: ''
}
export const secret = 'shared-secret';
export const file_dir = path.join(__dirname, `../data`); 
export const urls = {
    recogCardUrl: "http://127.0.0.1:20001/recog",
    barcodeUrl: "http://127.0.0.1:20001/barcode",
    fileServerUrlBase: "http://127.0.0.1:3000",
    getQuestionPath: function(examId, questionId, fname) {
        return "/exam/" + examId + "/" + questionId + "/" + fname;        
    }
}
/**
 * 系统目录结构
 * ├── exam
 │   └── 石室初中2016-2017学年度下期三月考试(或是id)
 │       └── 数学(或是id)
 │           ├── copies
 │           ├── splits
 │           │   ├── 1
 │           │   └── 2
 │           └── template
 │               ├── testexam.doc
 │               ├── testexam.jpg
 │               └── testexam.pdf
 ├── tmp
 │   ├── test.jpg
 │   └── testexam.jpg
 └── upload
 ├── QQ20170302-183050.png
 ├── testexam.doc
 └── timer.jpg
 *
 */
export class ExamCat {
    constructor(exameName, subjectName) {
        //基础目录
        this.base = path.join(__dirname, '../');
        this.root = path.join(this.base, './data');
        this.tmp = path.join(this.root, './tmp');
        this.upload = path.join(this.root, './upload');

        //考试相关目录
        this.exam = path.join(this.root, './exam');
        if(exameName) {
            if(typeof exameName == 'object') exameName = exameName.toString();
            this.examGroup = path.join(this.exam, exameName);
            this.examGroupTmp = path.join(this.examGroup, 'tmp');//如果在新建考试时，还没有选择科目，就上传了试卷，就把相关东西存在该文件夹下。
        }
        if(exameName && subjectName) {
            if(typeof subjectName == 'object') subjectName = subjectName.toString();
            this.examSubject = path.join(this.exam, exameName, subjectName);
            this.examTmpl = path.join(this.exam, exameName, subjectName, 'template');
            this.examCopy = path.join(this.exam, exameName, subjectName, 'copy');
            this.examSplit = path.join(this.exam, exameName, subjectName, 'split');
        }
    }

    static base() {
        return path.join(__dirname, '../');
    }

    static root() {
        return path.join(this.base(), './data');
    }

    static tmp() {
        return path.join(this.root(), './tmp');
    }

    static upload() {
        return path.join(this.root(), './upload');
    }

    static relative(fullPath) {
        return fullPath.replace(this.base(), '/');
    }

    static hostPath(_path) {
        if(_path.indexOf(this.base()) > -1) {
            return url.resolve(staticServ.host, this.relative(_path));
        }else {
            return url.resolve(staticServ.host, _path);
        }
    }
}

export const exam = {
    paperType: {
        A4: 'A4',
        A3: 'A3'
    },
    examType: {
        week: '周考',
        month: '月考',
        union: '区/市统考',
        homework: '课后作业',
        quiz: '小测验'
    },
    status: {
        unexceped: 0,//异常
        base: 1,//输入了基本信息,
        attached: 2,//上传了试卷
        dividing: 3,//正在圈题中
        completed: 4,//保存
        release: 5,//发布了
        uploading: 6,//图片上传中
        uploaded: 7,//图片上传完成
        slicing: 8,//正在切图
        sliced: 9,//切图完成
        marking: 10,//阅卷中
        marked: 11//阅卷结束
    }
};

export const userType = {
    admin: 1,
    teacher: 2,
    guarder: 3,
    student: 4
};

// user: 1,
// choice: 2,
// multiChoice: 3,
// judge: 4,
// blankFill: 5,
// Subjective: 6
export const question = {
    type: {
        user: 1,
        quser: 3,
        choice: 2,
        judge: 4,
        multiChoice: 5,
        Subjective: 6
    },
    direction: {
        horizontal: 1,
        vertical: 2
    },
    difficulty: {
        simple: {
            name: '简单',
            no: 1
        },
        middle: {
            name: '中等',
            no: 2
        },
        harder: {
            name: '难',
            no: 3
        }
    }
};

export const schoolType = {
    public: 1,
    private: 2,
    institute: 3
}